package com.example.demo.controller;

import com.example.demo.entity.EurekaBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * Created by think on 2017/7/20.
 */
@RestController
public class ConsumerController {

    @Autowired
    RestTemplate restTemplate;

    //GET第一种请求方式
    @RequestMapping(value = "ribbon-consumer",method = RequestMethod.GET)
    public String helloConsumer(){
        String body = restTemplate.getForEntity("http://HELLO-SERVICE/hello", String.class).getBody();
        return body;
    }

    //POST第一种请求方式 postForEntity函数
    @RequestMapping(value = "post-for-object",method = RequestMethod.POST)
    public Object helloConsumer(@RequestBody EurekaBean request){
        ResponseEntity<Object> responseEntity = restTemplate.postForEntity("http://HELLO-SERVICE/"+request.getUrl(),request.getObj(),Object.class);
        return responseEntity.getBody();
    }
}
